package org.example.design.chainofresponsibility.test2;

import org.example.util.Function;

/**
 * @author huangshen
 * @version 0
 * @description 抽象的请假责任处理类
 * @since 2022/2/10 13:46
 */
public abstract class AbstractLeaveHandler {

    /**直接主管审批处理的请假天数*/
    protected int directApproveThresholdDate = 1;
    /**部门经理处理的请假天数*/
    protected int deptManagerApproveThresholdDate = 3;
    /**总经理处理的请假天数*/
    protected int gManagerApproveThresholdDate = 7;
    /**
     * 最大请假天数
     */
    protected int max = 14;

    /**领导名称*/
    protected String handlerName;

    /**下一个处理节点（即更高级别的领导）*/
    protected AbstractLeaveHandler nextHandler;

    /** 确认审批流程 */
    protected abstract boolean resolve(LeaveRequest request);

    protected abstract void done(LeaveRequest request);

    /**设置下一节点*/
    public AbstractLeaveHandler setNextHandler(AbstractLeaveHandler handler){
        this.nextHandler = handler;
        return handler;
    }

    /**处理请假的请求，子类实现*/
    public void approve(LeaveRequest request){
        if(request.getLeaveDays() > max) {
            System.out.println("审批拒绝！");
            return;
        }
        if(resolve(request)) {
            done(request);
        }
        if(!Function.equalsNull(this.nextHandler)) {
            nextHandler.approve(request);
        }
    }

}
